//
//  QDPayTypePickerCell.swift
//  QDMetroClient
//
//  Created by YueWen on 2019/3/2.
//  Copyright © 2019 YueWen. All rights reserved.
//

import UIKit

/// 选择支付方式的cell
final class QDPayTypePickerCell: NWTableViewCell {
    
    /// 是否参与选择状态
    var actionSelectAnimated: Bool = true
    /// 方式的图片
    let headerImageView = UIImageView()
    /// 名称标签
    let titleLabel = UILabel()
    /// 选中的或者详情图片
    let selectImageView = UIImageView()
    /// 显示优惠政策
    let reminderLabel = RITLExternLabel()
    
    override func buildView() {
        super.buildView()
        
        bottomLineInset.right = 20
        bottomLineInset.left = 52
        bottomLineHeight = 0.5
        bottomLineView.backgroundColor = #colorLiteral(red: 0.9294117647, green: 0.9411764706, blue: 0.9333333333, alpha: 1)
        
        headerImageView.image = "pt_weixin".namedImage
        
        titleLabel.text = "微信"
        titleLabel.font = Font.regular.font(size: 16)
        titleLabel.textColor = QDColors.black
        
        selectImageView.image = "pt_unselected".namedImage
        
        reminderLabel.textColor = QDColors.orange
        reminderLabel.text = "微信支付5折优惠"
        reminderLabel.extensionSpace = 6
        reminderLabel.textAlignment = .center
        reminderLabel.font = Font.light.font(size: 11)
        reminderLabel.clipsToBounds = true
        reminderLabel.layer.cornerRadius = 8
        reminderLabel.layer.borderColor = QDColors.orange.cgColor
        reminderLabel.layer.borderWidth = 0.5
        
        contentView.addSubview(headerImageView)
        contentView.addSubview(titleLabel)
        contentView.addSubview(selectImageView)
        contentView.addSubview(reminderLabel)
        
        headerImageView.snp.makeConstraints { (make) in
            make.width.height.equalTo(24)
            make.top.equalToSuperview().offset(16)
            make.left.equalToSuperview().offset(20)
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(52)
            make.height.equalTo(22)
            make.top.equalToSuperview().offset(17)
        }
        
        selectImageView.snp.makeConstraints { (make) in
            make.right.equalToSuperview().inset(20)
            make.width.height.equalTo(24)
            make.top.equalToSuperview().offset(16)
        }
        
        reminderLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(52)
            make.height.equalTo(20)
            make.top.equalToSuperview().offset(46)
        }
    }
    
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        if !actionSelectAnimated { return }
        selectImageView.image = selected ? "pt_selected".namedImage : "pt_unselected".namedImage
    }
}

